<template>
  <div class="my">
    <div class="head">
      <img src="~@/assets/image/k.png" alt="">
      <div class="sign-in  iconfont icon-yonghu" v-show="!use" @click="toIneo"></div>
      <div class="sign-in2" v-show="use" @click="userQuit"><img src="~@/assets/image/0.png" alt=""></div>
    </div>
    <van-cell title="我的喜欢" icon="like-o" is-link @click="option=1" :arrow-direction="option==1?'down':''" />
    <!-- <van-cell title="我的评论" icon="more-o" is-link /> -->
    <van-cell title="我的点赞" icon="good-job-o" is-link @click="option=2" :arrow-direction="option==2?'down':''" />
    <van-cell title="我的评论" icon="comment-o" is-link @click="option=3" :arrow-direction="option==3?'down':''" />

    <div v-if="use" class="love">
      <div v-show="option==1">
        <van-tabs v-model="activeName" color="#568db4" background="#000" title-active-color="#fff"
          title-inactive-color="#ccc" ref="tabs">
          <van-tab title="mv" name="a">
            <div class="love" v-show="loveMv.length">
              <ul>
                <li class="van-ellipsis" v-for="(ele,index) in loveMv" :key="index"
                  @click="ShowPopup([true,ele.postid])">{{ele.title}}</li>
              </ul>
            </div>
            <van-empty image="search" description="无" v-show="!loveMv.length" />
          </van-tab>
          <van-tab title="专题" name="b">
            <div class="love" v-show="loveSpecial.length">
              <ul>
                <li class="van-ellipsis" v-for="(ele,index) in loveSpecial" :key="index" @click="toSpecial(ele.postid)">
                  {{ele.title}}</li>
              </ul>
            </div>
            <van-empty image="search" description="无" v-show="!loveSpecial.length" />
          </van-tab>
        </van-tabs>
      </div>
      <div class="comment" v-show="option==2">
        <div v-for="(ele,index) in loveComment" :key="index" class="comment-some">
          <div v-for="item in ele" :key="item.id" class="comment-one">
            <div class="com-img-box">
              <img v-lazy="item.img" alt="">
            </div>
            <div class="img-right">
              <p>{{item.name}}</p>
              <p>{{item.words}}</p>
            </div>
            <span>{{item.time|dateServer}}</span>
          </div>
        </div>
        <van-empty image="search" description="无点赞" v-show="!loveComment.length" />
      </div>
      <div class="my-comment" v-show="option==3">
        <ul v-show="myLoveComment.length">
          <li v-for="(ele,index) in myLoveComment" :key="index">{{ele.value}}
            <span>{{ele.tiem|dateServertwo}}</span>
          </li>
        </ul>
        <van-empty image="search" description="无评论" v-show="!myLoveComment.length" />
      </div>
    </div>
  </div>
</template>

<script>
  import {
    mapState,
    mapMutations
  } from "vuex"

  export default {
    name: 'my',
    data() {
      return {
        // finished: false,
        activeName: 'a',
        loveMv: [],
        loveSpecial: [],
        loveComment: [],
        option: 1,
        myLoveComment: []
      }
    },
    computed: {
      ...mapState(['collectionLists', 'comment', 'myCommennt', 'use'])
    },
    watch: {
      collectionLists: {
        immediate: true,
        handler(val) {
          val.filter(ele => {
            if (ele.type == "video") {
              if (this.loveMv.findIndex(item => item.postid == ele.postid) == -1) {
                this.loveMv.push(ele)
              }
            } else {
              if (this.loveSpecial.findIndex(item => item.postid == ele.postid) == -1) {
                this.loveSpecial.push(ele)
              }
            }
          })
        }
      },
      comment: {
        immediate: true,
        deep: true,
        handler(val) {
            val.filter(ele => {
          if (this.loveComment.findIndex(item => item.id == ele.id) == -1) {
            this.loveComment.push(ele)
          }
            })
        }
      },
      myCommennt: {
        immediate: true,
        handler(val) {
          this.myLoveComment = val
        }
      },
      option(val) {
        if (val == 1) {
          this.$nextTick(() => {
            this.$refs.tabs.resize();
          })
        }
      }
    },
    methods: {
      ...mapMutations(['ShowPopup', 'changeUse','delAll']),
      toSpecial(id) {
        console.log("专题文章", id);
        this.$router.push({
          name: 'Special',
          params: {
            id: id
          }
        })
      },
      toIneo() {
        this.$router.push({
          name: 'Ineo'
        })
      },
      userQuit() {
        this.changeUse(false)
        this.$router.push({
          name: 'Ineo'
        })
        localStorage.removeItem('vuex')
        sessionStorage.removeItem('user')
        this.delAll([])
      }
    }
  }
</script>

<style lang="less" scoped>
  .my {
    background-color: #000;

    .head {
      width: 100%;
      height: 210px;
      position: relative;

      img {
        width: 100%;
        height: 100%;
      }

      .sign-in,
      .sign-in2 {
        position: absolute;
        top: 38px;
        left: 50%;
        transform: translateX(-50%);
        background-color: #d9eee9;
        z-index: 9;
        line-height: 80px;
        width: 82px;
        border-radius: 50%;
        text-align: center;
        font-size: 32px;
        color: #fff;
      }

      .sign-in2 {
        height: 80px;
        overflow: hidden;

        img {
          width: 100%;
          height: 100%;
        }
      }
    }

    .van-cell {
      background-color: #000;
      color: #fff;
    }

    /deep/ .van-cell::after {
      border: none;
    }

    .love {
      color: #fff;
      text-align: center;
      line-height: 40px;
      font-size: 18px;
    }

    .comment {
      padding: 0 16px;

      .comment-some {
        width: 100%;

        .comment-one {
          display: flex;
          padding: 10px 0;

          span {
            font-size: 10px;
          }

          .com-img-box {
            width: 50px;
            height: 50px;
            border-radius: 50%;
            overflow: hidden;
            border: 1px solid #ccc;
            margin-right: 14px;

            img {
              width: 100%;
              height: 100%;
              object-fit: cover;
            }
          }

          .img-right {
            line-height: 26px;
            text-align: left;
            flex: 1;

            & p:nth-child(1) {
              font-size: 14px;
              font-weight: 600;
            }

            & p:nth-child(2) {
              font-size: 12px;
              color: #ccc;
            }
          }
        }
      }


      .van-empty {
        margin: 0 auto;
      }
    }

    .my-comment {
      ul {
        margin: 0 10%;
        padding: 15px 15px 10px 18px;
        background-color: #F0F0E3;

        border-radius: 5px;
        background: #E5E6D0 url('http://v.bootstrapmb.com/2019/8/l9wrq5715/images/bg.jpg') repeat 0 0;

        li {
          position: relative;
          background-color: #fff;
          line-height: 32px;
          color: #000;
          font-size: 14px;
          border-radius: 4px;
          overflow: hidden;
          padding-left: 36px;
          margin-bottom: 16px;
          // font-weight: bold;
          color: #696A52;
          background-color: #F0F0E3;
          border-radius: 5px;
          box-shadow: 0 1px 2px rgb(0, 0, 0, 15%), 0 1px 0 rgb(255, 255, 255, 75%) inset;

          span {
            position: absolute;
            top: 50%;
            left: 4px;
            transform: translateY(-50%);
            font-size: 10px;
          }
        }
      }

    }
  }
</style>